package com.xiaohe66.web.domain.im.agg;

import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.im.value.MessageCategory;
import com.xiaohe66.web.domain.im.value.MessageContext;
import com.xiaohe66.web.domain.im.value.MessageId;
import com.xiaohe66.web.domain.im.value.MessageState;
import com.xiaohe66.web.domain.im.value.MessageTitle;
import com.xiaohe66.web.integration.domain.Aggregate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

/**
 * @author xiaohe
 * @since 2023-08-09 16:00
 */
@Builder
@Getter
@ToString
@AllArgsConstructor
public class Message implements Aggregate<Message, MessageId> {

    @NonNull
    private final MessageId id;

    @NonNull
    private final AccountId createId;

    @NonNull
    private final AccountId accountId;

    /*@NonNull
    @Builder.Default
    private final MessageCategory category = MessageCategory.BIRTH;

    @NonNull
    private final MessageTitle title;*/

    @NonNull
    @Builder.Default
    private final MessageContext context = MessageContext.EMPTY;

    @NonNull
    @Builder.Default
    private MessageState state = MessageState.UNREAD;

    public void modifyRead() {
        this.state = MessageState.READ;
    }

    public void modifyUnread() {
        this.state = MessageState.UNREAD;
    }

    public void modifyState(MessageState state) {
        this.state = state;
    }

    @Override
    public boolean hasSameRootAttribute(Message other) {
        return other != null
                && state != other.state;
    }
}
